<template>
	<view v-if="userInfoData.realName==undefined">
		实名认证
		<uni-file-picker file-extname="png,jpg" :limit="1" fileMediatype="image" mode="grid"
			@select="selectFront" />
		<uni-file-picker  file-extname="png,jpg" :limit="1" fileMediatype="image" mode="grid"
			@select="selectBack" />
		<button @tap="commit">提交</button>
	</view>
	<view v-else>
		已实名认证
	</view>
</template>

<script setup lang="ts">
	import { ref } from 'vue'
	import { useMemberStore } from '../../stores';
	import { onLoad } from '@dcloudio/uni-app';
	import { User } from '/@/types/member';
	const memberStore = useMemberStore()
	let {userInfo}: User = memberStore.profile;
	const userInfoData=ref<User>({})
	onLoad(
		() => {
			userInfoData.value = userInfo;
			console.log(userInfoData.value.realName)
			console.log(memberStore.profile)
		})
	const image = ref([])

	const selectFront = (e : any) => {
		image.value.push(e.tempFilePaths[0])
	}
	const selectBack = (e : any) => {
		image.value.push(e.tempFilePaths[0])
	}
	const commit = () => {
	
		
		uni.uploadFile({
					url: '/app/uploadIdCard',
					header: {
						'Content-Type': 'multipart/form-data',
					},
					filePath: image.value[0],
		            name: 'file',
					formData: {
						idCardSide: 'front'
					},
					success: function (res) {
						const obj = JSON.parse(	res.data) ;
						userInfo.realName = obj["data"].realName
					},
					fail: function (err) {
						console.log('上传失败', JSON.stringify(err));
					}
		})
		
		uni.uploadFile({
					url: '/app/uploadIdCard',
					header: {
						'Content-Type': 'multipart/form-data',
					},
					filePath: image.value[1],
		            name: 'file',
					formData: {
						idCardSide: 'back'
					},
					success: function (res) {
						console.log('上传成功')
					},
					fail: function (err) {
						console.log('上传失败', JSON.stringify(err));
					}
		})
	}
	
</script>

<style>

</style>